// eslint-rules/api-name-suffix.js
/** @type {import('eslint').Rule.RuleModule} */
export default {
  meta: {
    type: 'problem',
    docs: {
      description: 'Enforce exported API names to end with "API"',
    },
    messages: {
      apiSuffix: 'Exported API name "{{name}}" must end with "API"',
    },
    schema: [], // no options
  },

  create(context: any) {
    return {
      ExportNamedDeclaration(node: any) {
        if (node.declaration?.type === 'VariableDeclaration') {
          for (const decl of node.declaration.declarations) {
            const name = decl.id.name
            if (!name.endsWith('API')) {
              context.report({
                node: decl.id,
                messageId: 'apiSuffix',
                data: { name },
              })
            }
          }
        }
      },
    }
  },
}
